ShadowRoot: innerHTML property

The innerHTML property of the ShadowRoot interface sets gets or sets the HTML markup to the DOM tree inside the ShadowRoot.

Note that some browsers serialize the < and > characters as &lt; and &gt; when they appear in attribute values (see Browser compatibility). This is to prevent a potential security vulnerability (mutation XSS) in which an attacker can craft input that bypasses a sanitization function, enabling a cross-site scripting (XSS) attack.

Value

A string.

When set to the null value, that null value is converted to the empty string (""), so sr.innerHTML = null is equivalent to sr.innerHTML = "".

Examples

Setting the innerHTML of a Shadow root

js
let customElem = document.querySelector("my-shadow-dom-element");
let shadow = customElem.shadowRoot;

shadow.innerHTML = "<strong>This element should be more important!</strong>";

Specifications

Specification
HTML
# dom-shadowroot-innerhtml

Browser compatibility